﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Royaumes_Libres.Database;

namespace Royaumes_Libres
{
    /// <summary>
    /// Page pour setter toutes les valeurs par défaut du monde et des buildings.
    /// </summary>
    /// <remarks>Patrick Chabot</remarks>
    public partial class adminworld : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.InitPage();
        }

        protected void InitPage()
        {
            this.pnlWorldBase.Controls.Add(cWorldsAdminSetting.GetWorldBase().GetControl(Page));

            cBuildingsAdmin[] buildings = cBuildingsAdmin.GetBuildings();
            foreach (cBuildingsAdmin building in buildings)
            {
                this.pnlBuildings.Controls.Add(building.GetControl(Page));
            }

            this.lblWorld.Text = cText.GetText("World");
            this.lblBuilding.Text = cText.GetText("Building");
            this.btnSave.Text = cText.GetText("Save");
            this.btnSave.Click += new EventHandler(btnSave_Click);
        }

        void btnSave_Click(object sender, EventArgs e)
        {
            foreach (Control ctl in this.pnlWorldBase.Controls)
            { if (ctl is ucWorldBase) { ((ucWorldBase)ctl).Save(); } }

            foreach (Control ctl in this.pnlBuildings.Controls)
            { if (ctl is ucBuildingAdmin) { ((ucBuildingAdmin)ctl).Save(); } }
        }
    }
}